﻿using System;
using IQIGame.Onigao.Framework;
using IQIGame.Onigao.Framework.Serialization;
using IQIGame.Onigao.GamePlay;
using LFloatMath.Math;

namespace IQIGame.Onigao.Logic
{
    public class SkillEffective_Cure : SkillEffective
    {
        protected override ISerializeCustomPOD OnExecute(SkillEffectiveData data, Unit target, SkillEffectiveContext context, int effectiveIndex, out SkillEffectiveResponse startResp)
        {
            startResp = null;
            var rAttacker = context.skill.executer;
            if (data.effectiveConfig.customConfig is SkillEffective_Cure_ConfigData rConfig)
            {
                var rCureResp = DamageController.TakeCure(rAttacker, target, rConfig.cureFormula, 1);
                return rCureResp;
            }

            return null;
        }

        protected override ISerializeCustomPOD OnActionExecute(SkillEffectiveData data, SkillActionNode action, Unit target, ref SkillEffectiveContext context, int effectiveIndex)
        {
            var rAttacker = context.skill.executer;
            if (action.customConfig is SkillEffectiveAction_Cure_ConfigData rConfig)
            {
                var nCure = rConfig.cure.GetValue(rAttacker, target, context);
                var rCureResp = DamageController.TakeCure(rAttacker, target, nCure, 1);

                context.AddRuntimeData(target, action.guid, BattleConst.RealCure, rCureResp.realCure.ToLFloat());
                var nCureOut = 0;
                if (rCureResp.realCure < rCureResp.finalCure)
                {
                    nCureOut = rCureResp.finalCure - rCureResp.realCure;
                }
                context.AddRuntimeData(target, action.guid, BattleConst.CureOut, nCureOut.ToLFloat());

                return rCureResp;
            }

            return null;
        }

#if UNITY_EDITOR
        public override string ToString(SkillCustomConfig config)
        {
            return "治疗";
        }
#endif
    }
}